class Student:

    def __init__(self):
        self.name = ''
        self.gender = ''
        self.age = 0

s1 = Student()
s1.name = '张三'
s1.gender = '男'
s1.age = 18

s2 = Student()
s2.name = '李四'
s2.gender = '女'
s2.age = 16

s = []
s.append(s1)
s.append(s2)

with open('data.txt', 'w', encoding='utf-8') as f:
    # f.write(s1.name + ' ' + s1.gender + ' ' + str(s1.age))

    # f-string 格式化字符串

    for item in s:
        f.write(f'{item.name} {item.gender} {item.age}\n')


    # f.write(s1.name)
    # f.write(' ')
    # f.write(s1.gender)
    # f.write(' ')
    # f.write(s1.age)




for item in s:
    with open('data1.txt', 'a', encoding='utf-8') as f:
        f.write(f'{item.name} {item.gender} {item.age}\n')




